from pydantic import BaseModel, ConfigDict
from pydantic.alias_generators import to_camel
from typing import Union, Optional, List
from datetime import datetime
from module_admin.annotation.pydantic_annotation import as_query, as_form


class DatasourceModel(BaseModel):
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    datasource_id: Optional[int] = None
    datasource_name: Optional[str] = None
    database_type: Optional[str] = None
    host: Optional[str] = None
    port: Optional[int] = None
    user: Optional[str] = None
    password: Optional[str] = None
    database: Optional[str] = None
    charset: Optional[str] = None
    client_encoding: Optional[str] = None
    connect_type: Optional[str] = None
    service_name: Optional[str] = None
    sid: Optional[str] = None
    dsn: Optional[str] = None
    encoding: Optional[str] = None
    nencoding: Optional[str] = None
    oracle_driver_path: Optional[str] = None
    jar_file_name: Optional[str] = None
    access_id: Optional[str] = None
    secret_access_key: Optional[str] = None
    project: Optional[str] = None
    endpoint: Optional[str] = None
    auth_mechanism: Optional[str] = None
    jdbc_url: Optional[str] = None
    program_name: Optional[str] = None
    create_by: Optional[str] = None
    create_time: Optional[datetime] = None
    update_by: Optional[str] = None
    update_time: Optional[datetime] = None
    remark: Optional[str] = None
    status: Optional[str] = None


class DatasourceQueryModel(BaseModel):
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)
    datasource_id: Optional[int] = None
    datasource_name: Optional[str] = None
    database_type: Optional[str] = None


@as_query
@as_form
class DatasourcePageQueryModel(BaseModel):
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)
    page_num: int = 1
    page_size: int = 50


class DeleteDatasourceModel(BaseModel):
    model_config = ConfigDict(alias_generator=to_camel)
    datasource_id_list: Optional[List[str]] = []

